import { createRouter, createWebHashHistory,RouteRecordRaw } from 'vue-router'
import { useUserStore } from '@/stores/user';
const routes = [
    {
        path: '/',
        component: () => import('@/views/index.vue'),

    },
    {
        path: '/control',
        component: () => import('@/views/controlmain.vue'),

    },
    {
        path: '/login',
        component: () => import('@/views/login.vue'),
        meta:{
            title:'登录'
        }
    },
    {
        path: '/register',
        component: () => import('@/views/register.vue'),
        meta:{
            title:'注册'
        }
    },
    {
        name: 'CourseDetail',
        path: '/CourseDetail/:id',
        component: () => import('@/views/CourseDetail.vue'),
        meta:{
            title:'课程'
        }
    },
    {
        path: '/study',
        component: () => import('../views/study.vue'),
        meta:{
            title:'成绩'
        },
        beforeEnter: (to, from, next) => {
            const userStore =useUserStore();

            if (userStore.pass==false) {
                next('/login');
            } else {
                next();
            }
        }

    },
    {
        path: '/personal',
        component: () => import('../views/personal.vue'),
        meta:{
           title:'个人信息'
        }
    },
    {
        path: '/controlmain',
        component: () => import('../views/controlmain.vue'),
        meta:{
            title:'个人信息'
        }
    }
]

const router=createRouter({
    history: createWebHashHistory(),
    routes,
})
// router.beforeEach((to, from, next) => {
//     const userStore = useUserStore();
//     const isAuthenticated = userStore.isPass;
//
//     if (
//         false
//         // to.meta.requiresAuth && !isAuthenticated
//     ) {
//         // 如果访问需要身份验证的页面，且用户未登录，则重定向到登录页面
//         next('/login');
//     } else {
//         // 允许访问页面
//         next();
//     }
// });
export default router